import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/match/widget/list_item_widget.dart';
import 'package:flutter_changdian_football/pages/match/widget/to_be_widget_controller.dart';
import 'package:flutter_changdian_football/pages/mine/user_store.dart';
import 'package:flutter_changdian_football/routers/app_routes.dart';
import 'package:flutter_changdian_football/utils/pull/pull_smart_refresher.dart';
import 'package:flutter_changdian_football/widget/default_page/custom_empty.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:get/get.dart';

/// 待开始
class ToBeWidget extends StatelessWidget {
  const ToBeWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<UserStore>(
      builder: (userStore) {
        if (userStore.isLogin == false) {
          return const CustomEmpty(text: '请先登录后再查看数据',);
        }
        return GetBuilder<ToBeWidgetController>(
          init: ToBeWidgetController(),
          builder: (toBeWidgetController) {
            return Container(
              margin: EdgeInsets.only(top: 10.w),
              child: RefreshWidget<ToBeWidgetController>(
                empty: Column(
                  children: [
                    Container(
                      width: double.infinity,
                      height: 240.w,
                      margin: EdgeInsets.symmetric(horizontal: 21.w),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(12.r)
                      ),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          SizedBox(
                            width: 260.w,
                            height: 138.w,
                            child: Image.asset('assets/images/img_kzt_01.png'),
                          ),
                          SizedBox(height: 12.w,),

                          SizedBox(
                            child: Text('暂无比赛信息', style: TextStyle(fontSize: 14.sp, color: const Color(0xffcccccc)),),
                          )
                        ],
                      ),
                    )
                  ],
                ),
                child: ListView.separated(
                  itemCount: toBeWidgetController.userMatchInfoList.length,
                  shrinkWrap: true,
                  padding: EdgeInsets.only(left: 21.w, right: 21.w, bottom: 30.w),
                  physics: const BouncingScrollPhysics(),
                  separatorBuilder: (context, index) {
                    return SizedBox(height: 20.w,);
                  },
                  itemBuilder: (BuildContext context, int index) {
                    return ListItemWidget(
                      userMatchInfoModel: toBeWidgetController.userMatchInfoList[index],
                      signUpTap: (matchId) {
                        toBeWidgetController.signUp(matchId);
                      },
                      goPayBillsTap: (matchId) {
                        Get.toNamed(AppRoutes.rechargePayment, parameters: {
                          'matchId': '$matchId'
                        });
                      },
                      cancelSignUpTap: (matchId) {
                        toBeWidgetController.cancelSignUp(matchId);
                      },
                    );
                  },
                ),
              ),
            );
          }
        );
      }
    );
  }
}